//------------------------------------------------------------------------
// <copyright file="Settings.cs" company="DevDir">
//   Copyleft (c) DevDir. No rights reserved.
// </copyright>
// <author>Nikita Sharov</author>
//------------------------------------------------------------------------

namespace DevDir.Mp3.Equilibrist.Controls
{
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Drawing;
  using System.Data;
  using System.Text;
  using System.Windows.Forms;
  
  public partial class MetaDataControl : BaseControl
  {
    private BindingSource dataSource;

    public MetaDataControl()
    {
      InitializeComponent();
    }

    public BindingSource DataSource
    {
      get 
      { 
        return this.dataSource; 
      }

      set
      {
        if (this.dataSource != value)
        {
          this.dataSource = value;
          this.OnDataSourceChanged();
        }
      }
    }

    protected virtual void OnDataSourceChanged()
    {
      this.artistTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "Artist", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.yearTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "Year", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.albumTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "Album", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.trackTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "Track", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.titleTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "Title", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.trackCountTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "TrackCount", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.discTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "Disc", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.discCountTextBox.DataBindings.Add(new Binding("Text",
        dataSource, "DiscCount", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.genreTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "Genre", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
      this.durationTextBox.DataBindings.Add(new Binding("Text",
        this.dataSource, "Duration", true,
        DataSourceUpdateMode.OnValidation, Settings.NullValue));
    }

    protected override void OnTextChanged(EventArgs e)
    {
      base.OnTextChanged(e);
      this.metadataGroupBox.Text = this.Text;
    }
  }
}
